<template>
  <div>
    <van-nav-bar title="文章详情" left-text="返回"  left-arrow @click-left="onClickLeft" />
    <div id="header" style="width: 100%;height:auto ; border: 1px solid silver;border-radius: 20px;">
      <div id="title">
        <h3>{{this.newsInfo.newsTetle}}</h3>
        <div>
          <span>来源:{{this.newsInfo.user.userTruename}}</span><br />
          <span>发布时间:{{this.newsInfo.newsDate}}</span>
        </div>
      </div>
    </div>
    <div id="body" style=" padding: 20px;">
      <span style="line-height: 30px;">
        {{this.newsInfo.newsContent}}
      </span>
    </div>
  </div>
</template>

<script>
import { Toast } from 'vant';
export default {
  
    data() {
        return {
          newsId: '',
          newsInfo: {}
        }
    },
    //生命周期 - 创建完成（访问当前this实例）
    created() {
     
  },
  methods: {
    findNewsById() {
      this.$axios.post('http://localhost:7000/news/findNewsById/' + this.newsId).then(res => {
        this.newsInfo = res.data.data;

      });
    },
    onClickLeft() {
      this.$router.go(-1)
    },
    timeout() { 
      var _this = this;
      const timer = setTimeout(function () {
        
        _this.$axios.post('http://localhost:7000/news/addIntegral', {'newsId': _this.newsId } ).then(res => {
          if (res.data.code == 1) {
            alert('已阅读1分钟,积分+10!')
          }

        });
      }, 5000);

    }
    
  },
   
    //生命周期 - 挂载完成（访问DOM元素）
    mounted() {
      this.newsId = this.$route.params.id;
      this.findNewsById();
      this.timeout();
    }
}
</script>
<style scoped>
/* @import url(); 引入css类 */

</style>